<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<div class="main-content">
    <div class="box box-main">
        <form id="maintainTechnologyForm" model="post" action="<c:url value="/web/admin/maintainTechnology/executeEdit.action?timeStamp=${timeStamp}"/>" method="post" class="form-horizontal" enctype="multipart/form-data">
            <div class="box-footer">
                <div class="row">
                    <div class="col-sm-offset-2 col-sm-12">
                        <button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> 保 存</button>&nbsp;

                        <button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="closeView()"><i class="fa fa-times"></i> 关 闭</button>
                    </div>
                </div>
            </div>
            <div class="box-body">
                <div class="form-unit">基本信息</div>
                <input type="hidden" name="id" value="${maintainTechnology.id}"/>
                <input type="hidden" name="oldId" value="${oldId}"/>
                <input type="hidden" name="createDate" value="${maintainTechnology.createDate}"/>
                <input type="hidden" name="code" value="${maintainTechnology.code}"/>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> 保养名称：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="name" name="name" value="${maintainTechnology.name}" maxlength="100" class="form-control required">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> 所属部门：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="selectOrganizationId" id="selectOrganizationId" name="selectOrganizationId" class="form-control required">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                所属专业：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="selectRootCatId" id="selectRootCatId" name="selectRootCatId" class="form-control">
                                <input type="hidden" id="rootCatId" value="-1">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                所属分类：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="selectCatId" id="selectCatId" name="selectCatId" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                预计工时(分)：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="estimateTime" name="estimateTime" value="${maintainTechnology.estimateTime}" maxlength="100" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                要求技能：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="requireSkill" name="requireSkill" value="${maintainTechnology.requireSkill}" maxlength="100" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                安全要求：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="safetyRequirement" name="safetyRequirement" value="${maintainTechnology.safetyRequirement}" maxlength="100" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                所需材料：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="requireMaterials" name="requireMaterials" value="${maintainTechnology.requireMaterials}" maxlength="100" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                所需工具：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="requireTools" name="requireTools" value="${maintainTechnology.requireTools}" maxlength="100" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                施工准备工作：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="prepareWork" name="prepareWork" value="${maintainTechnology.prepareWork}" maxlength="100" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label class="control-label col-sm-2" title="">
                                详细说明：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-9">
                                <textarea id="description" name="description" rows="4" maxlength="500" class="form-control ">${maintainTechnology.description}</textarea>
                            </div>
                        </div>
                    </div>
                    <div class="form-unit">维保内容</div>
                    <div class="col-xs-12">
                        <div class="form-group" style="margin-left: 6%">
                            <div class="col-xs-12">
                                <label class="btn  btn-primary" id="addData"><i
                                        class="icon-plus"></i>
                                    添加维保内容
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="ml10 mr10">
                        <table id="maintainDataGrid"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    $("#maintainTechnologyForm").validate({
        submitHandler: function(form){
            js.ajaxSubmitForm($(form), function(data){
                js.showMessage(data.msg);
                if(data.status == Global.NO){
                    closeView();
                    $('#dataGrid').dataGrid("refresh");
                }
            }, "json");
        }
    });

    $(function () {
        var selectRootCatId = $('#selectRootCatId').magicSuggest({
            allowFreeEntries: false,
            data: '<c:url value="/web/admin/facilityCat/getFacilityCatSelect.action?parentCatId=0&id=${rootCatId}" />',
            queryParam: 'q',
            valueField: "value",
            displayField: "text",
            maxSelection: 1,
            noSuggestionText: '',
            placeholder: '请选择',
            required: true,
            autoSelect: true,
            selectFirst: true,
            value: magicSuggestValue('${rootCatId}')
        });
        $(selectRootCatId).on('selectionchange', function (e, m) {
            $('#rootCatId').val(selectRootCatId.getValue()[0]);//更新最新的专业（既最上级类型ID）
            selectCatId.clear(true);
        });

        var selectCatId = $('#selectCatId').magicSuggest({
            allowFreeEntries: false,
            data: '<c:url value="/web/admin/facilityCat/getFacilityCatSelect.action?id=${maintainTechnology.facilityCat.id}" />',
            queryParam: 'q',
            valueField: "value",
            displayField: "text",
            maxSelection: 1,
            noSuggestionText: '',
            placeholder: '请选择',
            required: true,
            autoSelect: true,
            selectFirst: true,
            value: magicSuggestValue('${maintainTechnology.facilityCat.id}')
        });
        $(selectCatId).on('beforeload', function (e, m) {
            selectCatId.setDataUrlParams({"parentCatId":$('#rootCatId').val()});
        });

        var selectOrganizationId = $('#selectOrganizationId').magicSuggest({
            allowFreeEntries: false,
            data: '<c:url value="/web/admin/organization/getOrganizationListMagic.action?id=${maintainTechnology.organization.id}" />',
            queryParam: 'q',
            valueField: "value",
            displayField: "text",
            maxSelection: 1,
            noSuggestionText: '',
            placeholder: '请选择',
            required: true,
            autoSelect: true,
            selectFirst: true,
            value: magicSuggestValue('${maintainTechnology.organization.id}')
        });
    });

    function closeView() {
        layer.close(LayWin['wMaintainTechnology']);
    }
</script>
<script>
    $(document).ready(function () {
        // console.log(sd+"；列表")
        var mid = '${maintainTechnology.id}'
        var url = ""
        <%--console.log('${oldId}'+"；列表")--%>
        if (mid != null && mid != "" ) {
            url = "<c:url value="/web/admin/maintainData/listJson.action?id=${maintainTechnology.id}&timeStamp=${timeStamp}" />";

        } else {
            console.log('${oldId}'+"；列表")
            url = "<c:url value="/web/admin/maintainData/listJson.action?id=${oldId}&timeStamp=${timeStamp}" />";
        } if (mid != null && mid != "" ) {
            url = "<c:url value="/web/admin/maintainData/listJson.action?id=${maintainTechnology.id}&timeStamp=${timeStamp}" />";

        } else {
            console.log('${oldId}'+"；列表")
            url = "<c:url value="/web/admin/maintainData/listJson.action?id=${oldId}&timeStamp=${timeStamp}" />";
        }

        $("#maintainDataGrid").jqGrid({
            url:url,
            datatype: "json",
            multiselect: true,
            autowidth:true,
            rowNum: 100,
            colNames : ['操作','序号','维保项目','维保类别','输入类型','应用场景','是否临时数据'],
            colModel : [
                {name: 'action', index: 'action', label: "操作", align: 'center', editable: false, search: false, sortable: false, width: 60},
                {name : 'id',index : 'id', sortable: false, align: 'center',width : 100},
                {name : 'name',index : 'name', sortable: false, align: 'center',width : 100},
                {name : 'category',index : 'category', sortable: false, align: 'center',width : 100},
                {name : 'inputTypeEnum',index : 'inputTypeEnum', sortable: false, align: 'center',width : 100},
                {name : 'applicationScenarios',index : 'applicationScenarios', sortable: false, align: 'center',width : 100},
                {name : 'isTemp', sortable: false, align: 'center',width : 100}
            ],
            gridComplete: function() {
                var ids = $("#maintainDataGrid").jqGrid('getDataIDs');

                for (var i = 0; i < ids.length; i++) {
                    var maintainDataId = $("#maintainDataGrid").jqGrid('getRowData',ids[i]).id;
                    $("#maintainDataGrid").jqGrid('setRowData', ids[i], {
                        action : '<a href="javascript:;" class="btn btn-default btn-xs btnList" onclick="editPage('+maintainDataId+')"><i class="fa fa-pencil">编辑</i></a>&nbsp;' +
                        '<a href="javascript:;" class="btn btn-default btn-xs btnList" onclick=" submitRemove('+maintainDataId+')"><i class="fa fa-trash-o"></i>删除</a>&nbsp;'
                    });
                }
            },

            ajaxSuccess: function(data){

            }
        });
    });

    $("#addData").click(function () {
        vLayuiUtil.openLayerIframWindow('wMaintainData', '<c:url value="/web/admin/maintainData/maintainDataEdit.action?timeStamp=${timeStamp}" />', '添加维保内容',['70%', '95%'])
    })

    // 打开编辑窗口
    function editPage(id) {
        vLayuiUtil.openLayerIframWindow('wMaintainData', '<c:url value="/web/admin/maintainData/maintainDataEdit.action?timeStamp=${timeStamp}&id=" />'+id, '编辑维保内容',['70%', '95%'])
    }


    function submitRemove(id) {
        js.confirm('你确认要删除这条数据吗？', function () {
            $.ajax({
                type: 'post',
                url: "<c:url value="/web/admin/maintainData/delete.action" />",
                data: {"id": id},
                dataType: 'json',
                async: false,
                success: function (data) {
                    js.showMessage(data.msg);
                    $('#maintainDataGrid').dataGrid('refresh');
                },
                error: function () {
                    js.showMessage("出错了，请联系管理员");
                }
            });
        })
    }
</script>




